<template>
	<view>
	<!-- 秒杀 -->
		<view class="seckill">
			<!-- <view class="seckillTitle">限时秒杀</view> -->
			<u-tabs :list="list" active-color="#01a90c" :is-scroll="false" :current="current" @change="change"></u-tabs>
			<u-line color="#dddddd" />
			<!-- 内容 -->
			<scroll-view scroll-y="true" class="scroll-Y">
				<view class="seckillContent" v-if="current == 0">
					<view class="seckillItem" v-for="(item,index) in seckill" :key="index" @tap="goDetailPage(item.sk_id)">
						<view class="itemImg">
							<image :src="item.sk_goods_pic" mode=""></image>
						</view>
						<view class="itemInfo">
							<view class="productName">{{item.sk_goods_name}}</view>
							<view class="progress">
								<u-line-progress height="14" :show-percent="false" :striped="true" active-color="#ffa114" inactive-color="#fee9ca" :striped-active="true"></u-line-progress>
							</view>
							<view class="progressText">{{'已抢' + item.percent + '%'}}</view>
							<view class="price">
								<text>秒杀价￥</text>
								<text class="seckillPrice">{{item.sk_goods_price + ''}}</text>
								<text class="oldPrice">{{'￥'+ item.sk_goods_price_no}}</text>
								<view class="btn">立即抢购</view>
							</view>
						</view>
					</view>
					<u-loadmore :status="loadStatus" @loadmore="getSeckills()" />
				</view>
				<view class="seckillContent" v-if="current == 1">
					<view class="seckillItem" v-for="(item,index) in seckill" :key="index" @tap="goDetailPage(item.sk_id)">
						<view class="itemImg">
							<image :src="item.sk_goods_pic" mode=""></image>
						</view>
						<view class="itemInfo">
							<view class="productName">{{item.sk_goods_name}}</view>
							<view class="seckillTimer">
								{{item.sk_startime + '开抢'}}
							</view>
							<view class="price">
								<text>秒杀价￥</text>
								<text class="seckillPrice">{{item.sk_goods_price + ''}}</text>
								<text class="oldPrice">{{'￥'+ item.sk_goods_price_no}}</text>
								<view class="btn1">暂未开始</view>
							</view>
						</view>
					</view>
					<u-loadmore :status="loadStatus" @loadmore="getSeckills()" />
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import {
		getSeckill
	} from '../../api/index.js'
	import { useCounterStore } from '@/stores/index.js'
	export default {
		data() {
			return {
				list: [{
					name: '正在抢购'
				}, {
					name: '即将开始'
				}],
				current: 0,
				loadStatus:'loadmore',
				page:1,
				seckill:[]
			};
		},
		watch:{
			current:{
				handler(val,oldval){
					this.current = val
				},
				deep:true
			}
		},
		mounted() {
			this.getSeckills({state: 1,page:this.page})
		},
		onReachBottom() {
			//滚动到底部 加载更多
			this.loadStatus = 'loading';
			// 模拟数据加载
			this.page++
			setTimeout(() => {
				this.getGoodLists();
				this.loadStatus = 'loadmore';
			}, 1000);
		},
		methods:{
			change(index) {
				this.current = index;
				this.page = 1;
				this.getSeckills({state: index + 1,page:this.page});
				this.seckill = []
			},
			getSeckills(obj){
				let that = this
				getSeckill(obj).then(res=>{
					res.list.map(item=>{
						item["percent"] = ((item.sk_goods_total - item.sk_goods_inventory) / item.sk_goods_total).toFixed(2)
						that.seckill.push(item);
					})
					// console.log(that.seckill);
					if (res.list.length < 10) {
						that.loadStatus = 'nomore';
					}
				})
			},
			goDetailPage(id){
				// console.log('id',id);
				uni.navigateTo({
					url:'/page/point-details/point-details?id=' + id + '&mode=seckill'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	$color:#01a90c;
.seckillTitle{
	text-align: center;
	padding: 40rpx 0;
	font-size: 30rpx;
}
.seckillContent{
	padding: 0 20upx;
}
.seckillItem{
	display: flex;
	padding: 20upx 0;
	border-bottom: #e8e8e8 1upx solid;
	.itemInfo{
		flex: 1;
		margin-left: 20upx;
		position: relative;
	}
}
.itemImg{
	width: 220rpx;
	height: 220rpx;
	image{
		width: 100%;
		height: 100%;
	}
}
.progress{
	width: 200upx;
}
.progressText{
	color: #999;
	font-size: 20upx;
}
.seckillTimer{
	color: $color;
	font-size: 20upx;
	margin-top: 10upx;
}
.price{
	font-size: 22upx;
	color: #fe3333;
	// margin-top: 30upx;
	position: absolute;
	bottom: 0;
	width: 100%;
}
.seckillPrice{
	font-size: 32upx;
}
.oldPrice{
	color: #999999;
	text-decoration: line-through;
	margin-left: 10upx;
}
.disbtn,.btn,.btn1{
	float: right;
	width: 128upx;
	height: 46upx;
	line-height: 46upx;
	border-radius: 20upx;
	color: #fff;
	text-align:center;
}
.btn{
	background-color: #fe512a;
}
.btn1{
	background-color: #c6c6c6;
}
.disbtn{
	background-color: #c6c6c6;
}
</style>
